<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<style type="text/css">
		.input-append~label[class="error"]{
			float: left !important;
		}
		.input-append{
			float: left;clear: both!important;
		}
	</style>
	<title>设备管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
            var tiprequired ="<spring:message code='tip.required'/>";
            $("#companyName").attr("data-msg-required", tiprequired);
            $("#officeName").attr("data-msg-required", tiprequired);
            $("#typeName").attr("data-msg-required", tiprequired);
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					var eqId = $("#id").val();
					if(eqId == "" || eqId == null){
					var mac= $("#eleEquipmentCode").val();
					$.ajax({
						type: "POST",
						url: "${ctx}/equipment/eleEquipment/exists",
						data: {mac: mac},
						datatype: "json",
						success: function (data) {
							if(data.code == "0002"){
								alertx(data.msg);
							}else{
								loading('<spring:message code="common.subbmiting"/>');
                                timeVali($("#btnSubmit"));
								form.submit();
							}
						},
						error: function () {
							alertx("<spring:message code='tips.contactadmin' />");
							console.log(e);
						}
					});
					}else{
						loading('<spring:message code="common.subbmiting"/>');
						form.submit();
					}
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		
	</script>
</head>

<body>
	<ul class="nav nav-tabs">
		<li>
			<a href="${ctx}/equipment/eleEquipment/">
				<spring:message code="device.list"/>
			</a>
		</li>
		<li class="active">
            <a href="${ctx}/equipment/eleEquipment/form?id=${eleEquipment.id}">
                <shiro:hasPermission name="equipment:eleEquipment:edit">
					<c:if test="${not empty eleEquipment.id}">
						<spring:message code="device.modify"/>
					</c:if>
					<c:if test="${empty eleEquipment.id}">
						<spring:message code="device.add"/>
					</c:if>
				</shiro:hasPermission>
                <shiro:lacksPermission name="equipment:eleEquipment:edit">
					<spring:message code="device.info"/>
				</shiro:lacksPermission>
            </a>
        </li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="eleEquipment" action="${ctx}/equipment/eleEquipment/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.device.id"/>：</label>
			<div class="controls">
				<c:if test="${not empty eleEquipment.id}">
					<span style="font-size: 15px; font-weight: 700;">${eleEquipment.code}</span>
				</c:if>
				<c:if test="${empty eleEquipment.id}">
					<form:input id="eleEquipmentCode" path="code" htmlEscape="false" maxlength="255" class="input-xlarge required"/>
					<span class="help-inline">
						<font color="red">*</font>
					</span>
				</c:if>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code="device.name"/>：</label>
			<div class="controls">
					<form:input id="eleEquipmentName" path="name" htmlEscape="false" maxlength="255" class="input-xlarge required"/>
					<span class="help-inline">
						<font color="red">*</font>
					</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.group.branchoffice"/>：</label>
			<div class="controls">
                <shiro:hasRole name="admin">
                	<c:if test= "${not empty eleEquipment.id}">
						<sys:treeselect id="company" name="company.id" value="${eleEquipment.company.id}" labelName="company.name"
                                    labelValue="${eleEquipment.company.name}"
                                    title="<spring:message code='common.group.branchoffice'/>"
										url="/sys/office/treeDataForEquipment?type=1" notAllowSelectParent="true"
										notAllowSelectRoot="true" cssClass="required" allowInput="false"/>
					</c:if>
                   <c:if test= "${empty eleEquipment.id}">
					   <sys:treeselect id="company" name="company.id" value="${eleEquipment.company.id}" labelName="company.name"
                                    labelValue="${eleEquipment.company.name}"
                                    title="<spring:message code='common.group.branchoffice'/>"
									   url="/sys/office/treeDataForEquipment?type=1" notAllowSelectParent="true"
									   notAllowSelectRoot="true" cssClass="required" allowInput="false"/>
				   </c:if>
                    <span class="help-inline" style="margin-left: 5px"><font color="red">*</font> </span>
                </shiro:hasRole>
                <shiro:lacksRole name="admin">      
                <c:if test= "${not empty eleEquipment.id}">          
                    <input id="companyId" name="company.id" value="${eleEquipment.company.id}" type="hidden">
                    <input id="companyName" name="company.name" value="${eleEquipment.company.name}" type="hidden">
                    <label class="lbl">${eleEquipment.company.name}</label>
                    </c:if>
                    <c:if test= "${empty eleEquipment.id}">
                     <input id="companyId" name="company.id" value="${currentUser.company.id}" type="hidden">
                    <input id="companyName" name="company.name" value="${currentUser.company.name}" type="hidden">
                    <label class="lbl">${currentUser.company.name}</label>
                    </c:if>
                </shiro:lacksRole>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.group.group"/>：</label>
			<div class="controls">
				<shiro:hasPermission name="equipment:eleEquipment:group">
				 <c:if test= "${not empty eleEquipment.id}">          
					<sys:treeselect id="office" name="office.id" value="${eleEquipment.office.id}" labelName="office.name"
									labelValue="${eleEquipment.office.name}" title=""
									url="/sys/office/treeDataForEquipment?type=2" notAllowSelectParent="true" notAllowSelectRoot="true" cssClass="required" allowInput="false" disabled="disabled" />
					<span class="help-inline">
					<font color="red">*</font> </span>
					</c:if>
					<c:if test= "${empty eleEquipment.id}">
					<sys:treeselect id="office" name="office.id" value="${eleEquipment.office.id}" labelName="office.name"
									labelValue="${eleEquipment.office.name}" title=""
									url="/sys/office/treeDataForEquipment?type=2" notAllowSelectParent="true" notAllowSelectRoot="true" cssClass="required" allowInput="false" />
					<span class="help-inline"  style="margin-left: 5px">
					<font color="red">*</font> </span>
					</c:if>
				</shiro:hasPermission>
				<shiro:lacksPermission name="equipment:eleEquipment:group">
				<c:if test= "${not empty eleEquipment.id}">
					<input id="companyId" name="office.id" value="${eleEquipment.office.id}" type="hidden">
					<input id="companyName" name="office.name" value="${eleEquipment.office.name}" type="hidden">
					<label class="lbl">${eleEquipment.office.name}</label>
					</c:if>
						<c:if test= "${empty eleEquipment.id}">
					<input id="companyId" name="office.id" value="${currentUser.office.id}" type="hidden">
					<input id="companyName" name="office.name" value="${currentUser.office.name}" type="hidden">
					<label class="lbl">${currentUser.office.name}</label>
					</c:if>
				</shiro:lacksPermission>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code='menu.device.Equipment_Type'/>：</label>
			<div class="controls">
				<sys:treeselect id="type" name="type.id" value="${eleEquipment.type.id}"
								labelName="type.name" labelValue="${eleEquipment.type.name}"
								title="<spring:message code='menu.device.Equipment_Type'/>" url="/equipment/eleEquipmentType/treeData" cssClass="required"/>
				<span class="help-inline"  style="margin-left: 5px"><font color="red">*</font></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code='common.resolution'/>：</label>
			<div class="controls">
				<form:input path="width" htmlEscape="false" maxlength="255" class="input-mini digits " readonly="true" value="${eleEquipment.width}"/>
				*
				<form:input path="height" htmlEscape="false" maxlength="255" class="input-mini digits " readonly="true" value="${eleEquipment.height}" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code="device.orientation"/>：</label>
			<div class="controls">
				<form:input path="orientation" htmlEscape="false" maxlength="255" class="input-mini " readonly="true" value="${fns:getDictLabel(eleEquipment.orientation, 'orientation' ,'')}"/>
					
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code='common.remarks'/>：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="equipment:eleEquipment:edit">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="<spring:message code='common.save'/>"/>&nbsp;
			</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="<spring:message code='common.cancel'/>" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>